package com.itheima.conroller;

import com.itheima.domain.vo.SoulQuestionVo;
import com.itheima.service.SoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author fone
 * @date 2021/09/05
 */
@RestController
@RequestMapping("/soul")
public class SoulController {

    @Autowired
    private SoulService soulService;

    @GetMapping(name = "查询测灵魂问题", value = "/question/findByPage")
    public ResponseEntity findByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                     @RequestParam(value = "levelId") Integer levelId,
                                     @RequestParam(value = "keyword") String keyword) {
        return soulService.findByPage(pageNum, pageSize, levelId, keyword);
    }

    @GetMapping(name = "查询问题等级", value = "/question/level/findByPage")
    public ResponseEntity findQuestionLevelByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return soulService.findQuestionLevelByPage(pageNum, pageSize);
    }


    @PostMapping(name = "新增问题", value = "/question/add")
    public ResponseEntity addQuestion(@RequestBody SoulQuestionVo question) {

        return soulService.addQuestion(question);
    }


    @GetMapping(name = "根据问题 id 查询问题", value = "/question/findById")
    public ResponseEntity findQuestionById(@RequestParam(value = "id") Integer id) {
        return soulService.findQuestionById(id);
    }


    @PostMapping(name = "修改问题", value = "/question/update")
    public ResponseEntity updateQuestion(@RequestBody SoulQuestionVo question) {

        return soulService.updateQuestion(question);
    }

    @PostMapping(name = "删除问题", value = "/question/delete")
    public ResponseEntity deleteQuestion(@RequestBody Integer id) {

        return soulService.deleteQuestion(id);
    }


    @GetMapping(name = "根据问题 id 查询选项", value = "/question/option/findByQuestionId")
    public ResponseEntity findOptionByQuestionId(Integer questionId) {
        return soulService.findOptionByQuestionId(questionId);
    }

}
